package string;


import java.util.Random;
import java.util.Scanner;

public class Code {
    public static String generateVeriCode(int len){
        Random random=new Random();
        String code=" ";
        String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
        for (int i = 1; i <len ; i++) {
            int index=random.nextInt(str.length());
            char c=str.charAt(index);
            code+=c;
        }
        return  code;
    }

    public static void main(String[] args) {
        String code=generateVeriCode(6);

        Scanner scanner=new Scanner(System.in);

        System.out.println("请输入验证码："+code);
        String ncode=code.toUpperCase();
        String truecode= scanner.nextLine();
        truecode=truecode.toUpperCase();
        boolean p=ncode.equals(truecode);
        if(p){
            System.out.println("输入正确！");
        }
        else{
            System.out.println("输入错误！");
        }
    }
}
